package com.integral;

import com.alibaba.fastjson.JSON;
import com.yuhang.demo.util.PostUtil;
import com.yuhang.demo.util.SignUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

/**
 * @PROJECT_NAME: MyTest
 * @DESCRIPTION:
 * @author: yuhang
 * @DATE: 2020/8/3 14:52
 */
public class integralTest {

//    static String api = "http://127.0.0.1:46061/";

    static String api = "http://apijf.go2b2b.com/integral/";

    public static void main(String[] args) {
        try {
//            String result = listAllRules();
//            String result =  addRules();

//            for (int i = 0; i < 100; i++) {
//                entryAccount();
//            }
//            String result = entryAccount();

            String result =getSydByUserId();
//            String result =entryAccountStrength();
//            String result =getRulesByUserId();
//              String result= getSydByUserId();
//                String result =entryAccount();

//               String result=  consumeSyd();
//            String result=   backSyd();
//            String result=   scoreRefund();
//            String result=   getRecords();
//            String result= getSearchRecordRules();
//              String result =getStatisByUserId();
//              String result =  getSupplierSyd();
//            String result =  backGetRecords();
//            String result =  backAllRecords();
//            String result =   delBlackUser();
//            String result =getSydRate();
//            String result =getBlackList();
//            String result =addOrModiUserblack();
//            String result = getBlackLogList();
//            String result = getBlackLogList();
//            String result = repayScore();
//            String result =getExcel();
//            String result =  entryAccountByInit();
//            String result =   serviceWard();
//            String result =   getRewards();
//            String result =   addDirectSyd();

//            String result =   adSpreadConsume();
//            String result =   adSpreadBack();
//            String result =   backSignUpSyd();
              System.out.println(result);


//            Map<String, Object> params = new HashMap<String,Object>();
//            params.put("remark", "");
//            params.put("ruleCode", "advConsume");
//            params.put("targetId", "adpay_226260");
//            params.put("userId", "391155");
//            params.put("score", "25000");
//
//
//            long timestamp = Calendar.getInstance().getTime().getTime();
//            params.put("timestamp", String.valueOf(timestamp));
//            SignUtil s = new SignUtil();
//            String sign = s.signApp1B(params,"UTF-8");
//            params.put("sign", sign);

//            amount=480.0&remark=订购推广(订单号:231446)&ruleCode=advPay&sign=aa316736edf1db13f64f9c190ef513cc&targetId=adplay_231446&timestamp=1657037115222&userId=305704

//            String x= "http://integral:46060/integral/common/entryAccount";
//
//            Iterator<String> keys = params.keySet().iterator();
//            List<String> xx=new ArrayList<>();
//            while(keys.hasNext()){
//                String key = keys.next();
//                String target = params.get(key).toString();
//
//                xx.add(key+"="+target);
//            }

//            System.out.println(x+"?"+ StringUtils.join(xx,"&"));

        } catch (Exception e) {
            e.printStackTrace();
        }


    }

    public static String adSpreadBack() throws Exception {
        String url = api + "/integral/ad/adSpreadBack";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("targetId", "3e3cc248-df74-48a6-9083-584b082a96ec");
        params.put("score", "89");
        params.put("remark", "1111");
        params.put("userId", "305006");
        return PostUtil.httpPostIntegral(url, params);
    }

    public static String adSpreadConsume() throws Exception {
        String url = api + "/integral/ad/adSpreadConsume";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("targetId", UUID.randomUUID().toString());
        params.put("targetPayId", 1);
        params.put("score", "900");
        params.put("remark", "1111");
        params.put("userId", "305006");
        return PostUtil.httpPostIntegral(url, params);
    }


    public static String getSydRate() throws Exception {
        String url = api + "/integral/common/getSydRate";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("outPlatform", "GO2");
        return PostUtil.httpPostIntegral(url, params);
    }

    public static String consumeSyd() throws Exception {
        String url = api + "/integral/common/consumeSyd";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "265");
        params.put("targetId", "87");
        params.put("score", "2001");
        params.put("remark", "");
        params.put("ruleCode", "signUp");
        return PostUtil.httpPostIntegral(url, params);
    }


    public static String backSyd() throws Exception {
        String url = api + "/integral/common/backSyd";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "107255");
        params.put("targetId", "97159ee6-4fa4-45ec-a187-5c9b0b87860ax");
        params.put("score", "5000");
        params.put("remark", "373281");
        params.put("ruleCode", "advConsume");
        return PostUtil.httpPostIntegral(url, params);
    }

    public static String scoreRefund() throws Exception {
        String url = api + "/integral/common/scoreRefund";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "265");
        params.put("targetId", "4074648b-15b8-4c2e-82d4-6854ea83cc82x");
        params.put("score", "1");
        params.put("remark", "373281");
        params.put("ruleCode", "advConsume");
        return PostUtil.httpPostIntegral(url, params);
    }

    public static String getRecords() throws Exception {
        String url = api + "/integral/common/getRecords";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "235");
//        params.put("startTime","2020-10-01");
        params.put("startTime", "2020-1-01");
//        params.put("direction","IN");
        return PostUtil.httpPostIntegral(url, params);
    }

    public static String getSearchRecordRules() throws Exception {
        String url = api + "/integral/common/getSearchRecordRules";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "373281");
        return PostUtil.httpPostIntegral(url, params);
    }


    public static String getStatisByUserId() throws Exception {
        String url = api + "/integral/common/getStatisByUserId";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "265");
        return PostUtil.httpPostIntegral(url, params);
    }


    public static String getSydByUserId() throws Exception {
        String url = api + "/integral/common/getSydByUserId";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "265");
        return PostUtil.httpPostIntegral(url, params);
    }

    public static String getRulesByUserId() throws Exception {
        String url = api + "/integral/common/getRulesByUserId";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "265");
        return PostUtil.httpPostIntegral(url, params);
    }


    public static String entryAccount() throws Exception {
        String url = api + "/integral/common/entryAccount";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "305006");
        params.put("ruleCode", "advPay");
        params.put("amount", "200");
        params.put("remark", "advPay");
        params.put("targetId", UUID.randomUUID().toString());
        return PostUtil.httpPostIntegral(url, params);
    }
    public static String entryAccountByInit() throws Exception {
        String url = api + "/integral/common/entryAccountByInit";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "265");
        params.put("ruleCode", "advPay");
        params.put("amount", "10");
        params.put("remark", "在线交易");
        params.put("targetId", UUID.randomUUID().toString());
        return PostUtil.httpPostIntegral(url, params);
    }

    public static String serviceWard() throws Exception {
        String url = api + "/integral/common/serviceWard";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "265");
        params.put("wardType", "1");
        params.put("targetId", UUID.randomUUID().toString());
        return PostUtil.httpPostIntegral(url, params);
    }


    public static String addDirectSyd() throws Exception {
        String url = api + "/integral/common/addDirectSyd";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "265");
        params.put("beanNum", "99");
        params.put("expireTime", "1");
        params.put("ruleCode", "questionReward");
        params.put("targetId", UUID.randomUUID().toString());
        return PostUtil.httpPostIntegral(url, params);
    }


    public static String getRewards() throws Exception {
        String url = api + "/integral/common/getRewards";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "265");
        params.put("beanNum", "99");
        params.put("expireTime", "1");
        params.put("targetId", UUID.randomUUID().toString());
        return PostUtil.httpPostIntegral(url, params);
    }


    public static String backSignUpSyd() throws Exception {
        String url = api + "/integral/common/backSignUpSyd";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "265");
        params.put("score", "2001");
        params.put("targetId", "87");
        return PostUtil.httpPostIntegral(url, params);
    }
    public static String entryAccountStrength() throws Exception {
        String url = api + "/integral/common/entryAccountStrength";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", "107255");
//        params.put("ruleCode","orderPay");
        params.put("amount", "10");
        params.put("remark", "服务");
        params.put("targetId", UUID.randomUUID().toString());
        return PostUtil.httpPostIntegral(url, params);
    }

    public static String listAllRules() throws Exception {
        String url = api + "/integral/back/listAllRules";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("outPlatform", "E3E3");
        return PostUtil.httpPostIntegral(url, params);
    }

    public static String getSupplierSyd() throws Exception {
        String url = api + "/integral/back/getSupplierSyd";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("outPlatform", "E3E3");
        params.put("sortName", "USESCOREx");//AVAILSCORE  USESCORE
        params.put("sortType","0");
        return PostUtil.httpPostIntegral(url, params);
    }



    public static String backGetRecords() throws Exception {
        String url = api + "/integral/back/getRecords";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", 265);
        params.put("type", "ADVPAY");
        return PostUtil.httpPostIntegral(url, params);
    }

    public static String backAllRecords() throws Exception {
        String url = api + "/integral/back/getAllSupplierRecords";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("outPlatform", "E3E3");
        params.put("type", "GETMOBILE");
        return PostUtil.httpPostIntegral(url, params);
    }
    public static String delBlackUser() throws Exception {
        String url = api + "/integral/back/delBlackUser";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId","548244");
        params.put("operator","kwgk");
        return PostUtil.httpPostIntegral(url, params);
    }

    public static String getBlackList() throws Exception {
        String url = api + "/integral/back/getBlackList";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("outPlatform", "E3E3");
        return PostUtil.httpPostIntegral(url, params);
    }

    public static String addOrModiUserblack() throws Exception {
        String url = api + "/integral/back/addOrModiUserblack";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", 373281);
        params.put("ruleIds", "14,15,16,18");
        params.put("opeator", "373281");
        params.put("reason", "373281");

        return PostUtil.httpPostIntegral(url, params);
    }


    public static String getBlackLogList() throws Exception {
        String url = api + "/integral/back/getBlackLogList";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", 527160);
        return PostUtil.httpPostIntegral(url, params);
    }

    public static String getExcel() throws Exception {
        String url = api + "/getExcel";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("outPlatformEnum", "GO2");
        return PostUtil.httpPostIntegral(url, params);
    }


    public static String repayScore() throws Exception {
        String url = api + "/integral/back/repayScore";
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("userId", 30416);
        params.put("quantity", 11);
        params.put("remark", "");
        params.put("operator", "test");
        params.put("type", "1");
        params.put("ruleType", "1");
        return PostUtil.httpPostIntegral(url, params);
    }

    public static String test() throws Exception {
        String url = api + "/test";
        Map<String, Object> params = new HashMap<String, Object>();
        return PostUtil.httpPostIntegral(url, params);
    }



    public static String addRules() throws Exception {
        String url = api + "/integral/back/addRules";
        RulesAdd json = new RulesAdd();
        json.setName("名称(如入驻腾飞商家)");
        json.setOperator("系统");
        json.setOutPlatform("平台（1:go2,2:2mm,3:3e3e）");
        json.setCode("code");
        List<RulesDetailAdd> details = new ArrayList<RulesDetailAdd>();

        RulesDetailAdd rd = new RulesDetailAdd();
        rd.setRate("比例");
        rd.setType("商家身份：UNLIMITED-无限制,BASICS-基础商家，SERVICE-服务商家，STRENGTH-实力质造商家");//BASICS
        rd.setRemark("备注-立即到账");

//        RulesDetailAdd rd1 = new RulesDetailAdd();
//        rd1.setRate(new BigDecimal("1.5"));
//        rd1.setType("SERVICE");
//
//        RulesDetailAdd rd2 = new RulesDetailAdd();
//        rd2.setRate(new BigDecimal("2.0"));
//        rd2.setType("STRENGTH");

        details.add(rd);
//        details.add(rd1);
//        details.add(rd2);

        json.setDetails(details);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("data", JSON.toJSONString(json));
        System.out.println(JSON.toJSONString(json));
        return "";
//        return PostUtil.httpPostIntegral(url, params);
    }
}
